<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item prop="title">
        <el-input
          v-model="queryParams.title"
          placeholder="请输入活动标题"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['examine:active:add']"
        >发布活动
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="commonList">
      <el-table-column label="活动标题" align="center" prop="title" width="210px"/>
<!--      <el-table-column label="活动内容" align="center" prop="contents" :show-overflow-tooltip="true">-->
<!--        <template slot-scope="scope">-->
<!--          <div v-html="scope.row.contents"></div>-->
<!--        </template>-->
<!--      </el-table-column>-->
      <el-table-column label="发布人" align="center" prop="examineUserName"/>
      <el-table-column label="报名情况" align="center" prop="currentApprName">
        <template slot-scope="scope">
          <el-link type="primary" :underline="false" @click="submitClickHandler(scope.row.id)">
            <span style="color: red">{{ scope.row.submittedNum }}</span>{{ " / " + scope.row.allNum }}
          </el-link>
        </template>
      </el-table-column>
      <el-table-column label="发布时间" align="center" prop="pubTime" width="160px"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-search"
            @click="handleView(scope.row)"
            v-hasPermi="['examine:active:query']"
            v-if="scope.row.examineStatus >0"
          >查看
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleApprove(scope.row)"
            v-hasPermi="['examine:active:edit']"
          >修改
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['examine:active:remove']"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import quarter from "@/views/tool/quarter";
import halfyear from "@/views/tool/halfyear";
import {delActive, listEvaluate} from "@/api/examine/active/api";

export default {
  name: "EvaluateTable",
  dicts: ['examine_evaluate_status'],
  components: {
    quarter,
    halfyear,
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      cycleVal: '',
      // 通用考核表格数据
      commonList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        missionStatus: undefined,
        title: undefined,
        examineType: 3
      },
      examineYearOptions: {
        disabledDate: (time) => {
          const date = new Date()
          const year = date.getFullYear()
          const timeYear = time.getFullYear()
          return year > timeYear + 3
        }
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询通用考核列表 */
    getList() {
      this.loading = true;
      listEvaluate(this.queryParams).then(response => {
        this.commonList = response.rows;
        this.total = response.total;
      }).finally(()=>{
        this.loading = false;
      });
    },
    receiveClickHandler(id) {
      this.$router.push({path: "/active/receiveTable", query: {examineId: id}});
    },
    submitClickHandler(id) {
      this.$router.push({path: "/active/submitTable", query: {examineId: id}});
    },
    getCycleValue(data) {
      this.cycleVal = data;
    },
    getDictValue(data) {
      const obj = this.dict.type.examine_evaluate_status.find(d => Number(d.value) === data)
      if (obj) {
        return obj.label
      }
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.cycleVal = '';
      this.handleQuery();
    },
    handleDelete(row) {
      let self=this
      this.$modal.confirm('是否确认删除活动标题为"' + row.title + '"的数据？删除后无法恢复').then(function () {
        delActive(row.id).then(() => {
          self.getList()
          self.$modal.msgSuccess("删除成功");
        })
      })
    },
    handleAdd() {
      this.$router.push({path: "/active/add"});
    },
    /**查看按钮操作 */
    handleView(row) {
      this.$router.push({path: "/active/evaluateSubView", query: {id: row.id, isApprJump: false}});
    },
    /**修改操作 */
    handleApprove(row) {
      this.$router.push({path: "/active/add", query: {id: row.id}});
    }
  }
};
</script>
